index_app.controller("comm_detailed_edit", function ($scope,$http,$routeParams,$timeout) {
	$scope.params=$routeParams;
	$scope.detailedKey = $scope.params.key;

	if($scope.detailedKey == "null"){
	    $scope.other = true;
   	}

	$http.post("commodityDetailed/selectByKey?detailedKey="+$scope.detailedKey).then(function(response){
		//数据源
		$scope.commDetailed = response.data;
	});

		$timeout(function(){
          //获取所有商品类别
            $http.post("commodityType/selectAll").then(function(response){
                //数据源
                $scope.commTypeList =  response.data;
                $("#skuType").select2();
            });
        },100)
	$scope.returnList = function(){
		$("#returnButton").attr("href","#comm_detailed_list");

	};

	$scope.master = null;
	$scope.reset = function() {
		$scope.commDetailed = angular.copy($scope.master);
	};
	$scope.reset();



	//用户信息修改页面中保存操作
	$scope.commodityDetailedUpdate = function(commDetailed){
        console.log(commDetailed);
		if($("#skuType").val() == null){
			$scope.skuType = "0";
		} else {
			$scope.skuType = $("#skuType").val().split(":")[1];
		}

		commDetailed.skuType = null;

		$http({
			method  : 'POST',
			url     : 'commodityDetailed/saveOrUpdateCommDetal?typeKey='+$scope.skuType,
			params    : commDetailed,//传递真个对象到后台
			headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
		}).success(function(data) {
			if(data == 1){
				//添加保存标题样式
				$scope.title = '<h4 class="easyDialog_title" id="easyDialogTitle"><i class="icon-ok green"></i> <a href="javascript:void(0)" title="关闭窗口" class="close_btn" id="closeBtn">&times;</a>保存</h4>';
				//保存成功内容
				$scope.toolTip = "保存成功";
				//弹窗
				toolTipDialog();
				$scope.success = true;

			} else {
				$scope.title = "保存";
				$scope.toolTip = "保存失败";
			}
		});
	};

	function toolTipDialog(){
    		easyDialog.open({
    			container : {
    				header : $scope.title,
    				content : $scope.toolTip,
    				yesFn : $scope.toolFn,
    				noFn : false
    			},
    			fixed : false
    		});
    	}
    	//弹窗中确定按钮事件
        	$scope.toolFn = function(){
        		if( $scope.success){//成功
        			window.location.href="#comm_detailed_list";
        		}
        		return true;
        	}

})